#include<stdio.h>
#include<stdlib.h>


int det2(int x1,int x2,int y1,int y2){
  return x1*y2-x2*y1;
}

int det3(int mp[3][3]){
  int l1,l2,l3;
  l1=mp[0][0]*det2(mp[1][1],mp[1][2],mp[2][1],mp[2][2]);
  l2=mp[0][1]*det2(mp[1][0],mp[1][2],mp[2][0],mp[2][2]);
  l3=mp[0][2]*det2(mp[1][0],mp[1][1],mp[2][0],mp[2][1]);
  return l1-l2+l3;
}

int main(){

  int t,ans;
  printf("What type matrix do you want to calculate? Input '2' for 2*2 and '3' for 3*3.Input control+z to stop the program.\n");
  
  while(scanf("%d",&t)!=EOF){
    printf("Please input a11 a12 ...... and spaces are used between numbers.\n");
    if(t==2){
      int a11,a12,a21,a22;
      scanf("%d%d%d%d",&a11,&a12,&a21,&a22);
      ans=det2(a11,a12,a21,a22);
    }

    if(t==3){
      int m[3][3];
      for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
          scanf("%d",&m[i][j]);
        }
      }
      ans=det3(m);
    }

    printf("The answer is %d.\n",ans);
  }

  return 0;  
}